package com.example.dmallOrder.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dmall.sdk.ApiException;
import com.dmall.sdk.DefaultDmallClient;
import com.dmall.sdk.DmallClient;
import com.dmall.sdk.domain.req.bofc.OutboundDetailReq;
import com.dmall.sdk.request.bofc.BofcBizOutboundReqRequest;
import com.dmall.sdk.response.DmallResponse;
import com.example.dmallOrder.config.DmallConfig.DmallConstant;
import com.example.dmallOrder.config.cache.TiktokAccessTokenCacheEnum;
import com.example.dmallOrder.config.cache.TiktokCacheManager;
import com.example.dmallOrder.config.cache.TiktokCacheManagerEnum;
import com.example.dmallOrder.entity.DmallMsgOrder;
import com.example.dmallOrder.mapper.DmallMsgOrderDao;
import com.example.dmallOrder.service.DmallMsgOrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * DMALL-MQ-订单表 服务实现类
 *
 * @author 
 * @since 2025/07/14
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DmallMsgOrderServiceImpl extends ServiceImpl<DmallMsgOrderDao,DmallMsgOrder>implements DmallMsgOrderService {

    @Resource
    TiktokCacheManager tiktokCacheManager;
    private final DmallMsgOrderDao dmallMsgOrderDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long create(DmallMsgOrder dmallMsgOrder ) {
        dmallMsgOrderDao.insert(dmallMsgOrder);
        return Long.valueOf(dmallMsgOrder.getId());
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(DmallMsgOrder dmallMsgOrder) {
        dmallMsgOrderDao.updateById(dmallMsgOrder);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Long id) {
        dmallMsgOrderDao.deleteById(id);
    }

    @Override
    public DmallMsgOrder get(Long id) {
        return dmallMsgOrderDao.selectById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void WmsToDmall() {
//        String token =tiktokCacheManager.getCache(TiktokCacheManagerEnum.AccessCache, TiktokAccessTokenCacheEnum.AccessToken.getCode());
//        DmallClient dmallClient = new DefaultDmallClient(DmallConstant.DMALL_BOFC_BIZ_OUTBOUND_REQ_URL.getValue(), token,DmallConstant.APP_KEY.getValue() ,DmallConstant.APP_SECRET.getValue() );
//        BofcBizOutboundReqRequest request = new BofcBizOutboundReqRequest();
//        request.setBillNo("566663210");
//        List<OutboundDetailReq> detailReqs = new ArrayList<>();
//        OutboundDetailReq outboundDetailReq = new OutboundDetailReq();
//        detailReqs.add(outboundDetailReq);
//        request.setDetailList(detailReqs);
//        request.setOutboundTime();
//        request.setOutboundUserId(9527);
//        request.setOutboundUserName("张三");
//        request.setPoNo("PO4545");
//        request.setStorageLocation("0001");
//        request.setStorageLocationName("0001库存地");
//        request.setUuid("唯一ID");
//        request.setPredictDate();
//        request.setTransferMode(1);
//        request.setErpPurchaseId("23333");
//        request.setTransferCustomerPalletHead(1);
//        DmallResponse response = null;
//        try {
//            response = dmallClient.execute(request);
//        } catch (ApiException e) {
//            throw new RuntimeException(e);
//        }
//        System.out.println(response);
    }


}
